import mplfinance as mpl
import pandas as pd
import tushare as ts
import numpy as np
from scipy import stats
from matplotlib import pyplot as plt
import warnings
warnings.filterwarnings('ignore')


class tusharekline:
    def __init__(self):
        self.pro = ts.pro_api('0ba8feef618e5db7b1ebb65538fe51e4aef69fb3cbf709d44128f313')
        self.columnname =['symbol','Date','Open','High','Low','Close','Pre_Close','Change','Pct_chg', 'Volume','Amount']
        
    def getKlines(self, symbol,start_date='20200101', end_date='20210423'):
        dfday = self.pro.daily(ts_code=symbol, start_date=start_date, end_date=end_date)
        dfday.columns= self.columnname
        dfday.index = pd.to_datetime(dfday.Date)
        dfday.drop(columns=['Date'], inplace=True)
        dfday['Return'] = dfday['Close'] / dfday['Pre_Close'] - 1
        return dfday